<?php

/**
 * LoginWidget class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Wednesday, June 15, 2011. 11:38 PM
 */
class LoginWidget extends CWidget {

	private $_model;

	public function init() {
		$this->_model = new LoginForm;
		if (isset($_POST['LoginForm'])) {
			$this->_model->attributes = $_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if ($this->_model->validate() && $this->_model->login()) {
				$this->controller->refresh();
			}
		}
	}

	public function run() {
		$this->render('login', array('model'=>$this->_model));
	}

}
